package com.youlai.boot.modules.game.controller;

import com.youlai.boot.common.result.Result;
import com.youlai.boot.modules.game.service.OssService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@Tag(name = "文件上传接口")
@RestController
@RequestMapping("/v1/oss")
@RequiredArgsConstructor
@Slf4j
public class OssController {

    private final OssService ossService;

    @Operation(summary = "上传文件")
    @PostMapping("/upload")
    public Result<String> uploadFile(@RequestParam("file") MultipartFile file) {
        if (file.isEmpty()) {
            return Result.failed("上传文件不能为空");
        }
        String url = ossService.uploadFileAvatar(file);
        if (url != null) {
            return Result.success(url);
        } else {
            return Result.failed("文件上传失败");
        }
    }
} 